<template>
  <!-- <el-card class="search-frame"> -->
  <div class="search-frame">
    <el-form ref="formRef" v-bind="$attrs" :inline="true" @keyup.enter.native="querySearch(1, pageSize)">
      <el-button class="btnName" v-hasPermi="hasPermi" v-show="btnName" type="primary" @click="btnClick">{{ btnName }}</el-button>
      <div class="clearfix">
        <slot></slot>
        <el-form-item class="fr" v-if="searchFunc" style="margin-right:6px;margin-bottom:0">
          <el-button type="primary" @click="querySearch(1, pageSize)">查询</el-button>
          <el-button type="primary" @click="resetform('form')">重置</el-button>
        </el-form-item>
        <slot name="search-footer" v-else></slot>
      </div>
    </el-form>
  </div>
  <!-- </el-card> -->
</template>
<script setup lang="ts">
import useAppStore from '@/store/modules/app';
const appStore = useAppStore();

const props = defineProps({
  btnName: {
    type: String,
    default: ''
  },
  btnFunc: {
    type: Function
  },
  hasPermi: {
    type: Array,
    default: _ => []
  },
  showLabel: {
    type: Boolean,
    default: false
  },
  searchFunc: {
    type: Function
  },
  reset: {
    type: Function
  },
  resetformFun: {
    type: Function
  }
});
const formRef = ref();
async function querySearch(pageNo, pageSize) {
  (await formRef.value) && formRef.value.validate();
  appStore.setPageNum(1);
  props.searchFunc(pageNo, pageSize);
}
// 重置查询表单
function resetform(formName) {
  appStore.setPageNum(1);
  appStore.setPageSize(15);
  formRef.value && formRef.value.resetFields();
  // 路外过滤车场---张君保
  if (props.resetformFun) {
    props.resetformFun();
  } else if (props.searchFunc) {
    if (props.reset) {
      props.reset();
    }
    props.searchFunc(appStore.pageNum, appStore.pageSize);
  }
}
function btnClick() {
  if (props.btnFunc) props.btnFunc()
}
</script>
<script lang="ts">
export default {
  name: 'search-frame'
};
</script>

<style lang="scss" scoped>
.search-frame {
  margin-bottom: 12px;
  overflow: initial;
  .el-form {
    display: flex;
    // align-items: center;
    .btnName {
      width: 80px !important;
      height: 32px !important;
      line-height: 32px;
      margin-right: 10px;
      &.el-button {
        width: 100px;
      }
    }
  }
  .clearfix {
    width: 100%;
  }

  .dash-line {
    margin-bottom: 4px;
    border-bottom: 1px dashed #eaeaea;
  }


}

.search-frame :deep(.el-card__body) {
  padding: 12px 20px;
}
.search-frame :deep(.el-input__inner) {
  height: 32px;
}
.search-frame :deep(.el-button) {
  line-height: 32px;
}
</style>
